<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

<script type="text/javascript">
var loadNoteOpts = {
    msg : "<bean:message key="note.load.msg" bundle="errors"/>",
    boxTitle : "<bean:message key="note.load.boxTitle" bundle="errors"/>",
    msgStatus: "<bean:message key="note.load.msgStatus" bundle="errors"/>"
};

$(document).ready(function() {
	var options = {
	   target:        '#validationbox',   
	   beforeSubmit:  function () {
	                      $('.accordion').empty();
	                      $('.accordion').html('<img alt="<bean:message key="saving.message"/>" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="saving.message"/>');
	                  }, 
	   success:       function () {
	                	  $('.accordion').html('<img alt="<bean:message key="wait.message"/>" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="wait.message"/>');
	                	  loadNote('${pageContext.request.contextPath}/ticket/loadticketnote.do', '<bean:write name="noteform" property="ticketID"/>');
	                  },
	   error:         function () {
	                      showErrorDialog('#dialog', 
	                             { msg : "<bean:message key="note.save.msg" bundle="errors"/>",
	                    	       boxTitle : "<bean:message key="note.save.boxTitle" bundle="errors"/>",
	                    	       msgStatus: "<bean:message key="note.save.msgStatus" bundle="errors"/>" });
               	       
	                      loadNote('${pageContext.request.contextPath}/ticket/loadticketnote.do', '<bean:write name="noteform" property="ticketID"/>');
	                  }  
	};

    $('#form_note').ajaxForm(options);
    
	/* jQuery textarea resizer */
    $('textarea.resizable:not(.processed)').TextAreaResizer();
});
</script>
<div class="innerNote">
	<p class="innerNoteNote">Note</p>
	<p class="delete" title="<bean:message key="ticket.note.button.close" bundle="ticket"/>">X</p>
</div>
<div class="accordionResizer" style="padding:0px; float:left; padding-bottom:11px; width:500px;">
	<div class="accordion">
	   <c:forEach items="${requestScope.comments}" var="item">
	       <h3><a href="#" title="${item.writtenBy.profile.firstName} ${item.writtenBy.profile.lastName}">${item.writtenBy.username} - ${item.commentDate}</a></h3>
	       <div>
               <p>${item.content}</p>
           </div>
	   </c:forEach>
	</div>
	
	<span style="margin:2px auto;"></span>
</div>

<div class="conteinerNoteResponse">
    <html:form styleId="form_note" styleClass="appnitroFormNote" action="/ticket/addticketnote.do">
    <html:textarea styleId="commentText" styleClass="resizable responseNote" property="commentText"></html:textarea>
	<div class="saveNote">
	   <html:hidden styleId="ticketID" property="ticketID"/>
	   <html:submit styleClass="saveNoteButton" styleId="saveButton">
	       <bean:message key="button.save" />
	   </html:submit>
	</div>
	</html:form>
</div>